package com.chilli.cosima.common;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.chilli.cosima.utils.SpringUtils;

public class SystemStartUp implements ServletContextListener
{
	private static Log log = LogFactory.getLog(SystemStartUp.class);

	public void contextDestroyed(ServletContextEvent arg0)
	{

	}

	/**
	 * 加载
	 * 
	 * @param arg0
	 */
	public void contextInitialized(ServletContextEvent arg0)
	{
		log.info("*********SystemStartUp***********");
		ApplicationContext applicationContext = WebApplicationContextUtils
				.getWebApplicationContext(arg0.getServletContext());

		log.info("applicationContext=" + applicationContext);

		SpringUtils.setApplicationContext(applicationContext);

		log.info("bean=" + SpringUtils.getBean("userDao"));

		log.info("webapp.root=" + System.getProperty("webapp.root"));

		log.info("start to init log4j...");

		String filePath = Thread.currentThread().getContextClassLoader()
				.getResource("/log4j.properties").getPath();

		PropertyConfigurator.configure(filePath);

		log.info("log4j init OK.");

	}

}
